<?php
/**
*	用户管理
*/ 
class mode_zhuanjiaClassAction extends inputAction{
	
	//保存前处理
	protected function savebefore($table, $cans, $id, $addbo){
	}
	
	//保存后处理
	protected function saveafter($table, $cans, $id, $addbo){
		$log = m('a_zhuanjia')->getone('id ='.$id);
		if($log && $log['type']){
            $logarry = explode(",",$log['type']);
            m('a_zj_type')->delete("zid=".$id);
            foreach ($logarry as $key => $value) {
            	$addArr = array(
                    "type"=>$value,
                    "zid"=>$id
                );
            	m('a_zj_type')->insert($addArr);
            }
		}
	}

	public function zhuanjiatypedata()
	{   
		$sql = 'SELECT `id` as value,`title` as name FROM `[Q]a_zhuanjia_type`  where 1=1 order by id desc ';
		$list = $this->db->getall($sql);
		if(empty($list)) $list = array(array('value' => 0, 'name' => ''));
		return $list;
	}
	
	//组数据源
	public function groupdata()
	{
		return m('sjoin')->getgrouparrs();
	}
	
	//生成列表页，数据读取后处理
	protected function storeafter($table, $rows)
	{
		$barr['rows'] = $rows;
		if($this->loadci==1 && $this->post('atype')=='txlmy'){
			$this->depta = array();
			$drows = m('dept')->getdata($rows);
			$barr['deptdata'] = $this->depttreeshu($drows,'0');
		}
		return $barr;
	}
	
	//更新在线的状态，token10分钟内都是在线
	protected function storebefore($table)
	{
		m('login')->updateallonline();
	}
	
	//组织结构活动得到树形数据
	private function depttreeshu($rows, $pid)
	{
		$barr = array();
		foreach($rows as $k=>$rs){
			if($rs['pid']==$pid){
				$rs['children'] = $this->depttreeshu($rows, $rs['id']);
				$rs['expanded'] = $pid=='0';
				$barr[] = $rs;
			}
		}
		return $barr;
	}
	
	//修改上级
	public function editsuperAjax()
	{
		$sna	= $this->post('sna');
		$sid	= $this->post('sid');
		$xid	= $this->post('xid');
		m('admin')->update(array(
			'superid' => $sid,
			'superman' => $sna,
		),"`id` in($xid) and id not in($sid)");
		
		m('admin')->updateinfo(); //更新
		return 'ok';
	}
}	
			